package org.scc.dao;

import java.util.List;

import org.scc.model.Resource;

public class ResourceDao extends BaseDao{
	
	@Override
	protected String getMapper(String methodName) {
		return "org.scc.sqlmap.ResourceMapper." + methodName;
	}
	
	/**
	 * 新增一级资源
	 * @param resource
	 */
	public void addFirstLevel(Resource resource){
		insert( getMapper("addFirstLevel"), resource, "add resource error");
	}
	
	/**
	 * 新增二级资源
	 * 资源的父资源不能为空
	 * @param resource
	 */
	public void addSecondLevel(Resource resource){
		insert( getMapper("addSecondLevel"), resource, "add resource error");
	}
	
	/**
	 * 更新资源
	 * @param resource
	 */
	public void update(Resource resource){
		update(getMapper("update"), resource, "update resource error");
	}
	
	/**
	 * 删除资源
	 * @param ids
	 */
	public void delete(String ids){
		delete(getMapper("delete"), ids, "delete resource error");
	}
	
	/**
	 * 加载资源
	 * @param id
	 * @return
	 */
	public Resource load(int id){
		return selectOne(getMapper("load"), id, "load resource error");
	}
	
	/**
	 * 查询所有资源
	 * @return
	 */
	public List<Resource> findAll(){
		return selectList(getMapper("findAll"), "findAll resource error");
	}
	
	public List<Resource> findFirstLevel(){
		return selectList(getMapper("findFirstLevel"), "find first level resource error");
	}
	
	public List<Resource> findSecondLevel(int id){
		return selectList(getMapper("findSecondLevel"), id, "find second level resource error");
	}
}
